<!--
 * @Description: 去零弹窗
 * @Autor: 何兴家
 * @Date: 2021-01-12 10:27:37
 * @LastEditors: 何兴家
 * @LastEditTime: 2021-01-29 11:10:43
-->
<template>
  <div>
    <FormPanel ref="formPanel" :list="formList" :cols="1" :isSubmitBtn="false"></FormPanel>

    <div class="dialogBottmView">
      <el-button @click="handleCancel">取消</el-button>
      <el-button type="primary" @click="handleConfirm">确定</el-button>
    </div>
  </div>
</template>

<script>
import _ from 'lodash';
import { dictionary } from '@/utils/dictMixin';
import { confirmAction, notifyAction, findFormItem, findTableItem } from '@/utils';

export default {
  props: ['costInfoObj', 'limit'],
  mixins: [dictionary],
  data() {
    this.limitAmount = Infinity; // 去零限额
    return {
      formList: this.createFormList()
    };
  },
  mounted() {
    console.log(this.costInfoObj);
    this.limitAmount = _.isNil(this.limit) ? Infinity : +this.limit;
    findFormItem(this.formList, 'calcReceiveAmount').initialValue = this.costInfoObj.calcReceiveAmount;
    findFormItem(this.formList, 'subObbAmount').initialValue = this.costInfoObj.subObbAmount;
    findFormItem(this.formList, 'subObbAmount').max = this.costInfoObj.calcReceiveAmount;
  },
  methods: {
    createFormList() {
      return [
        {
          type: 'INPUT',
          label: '实收金额',
          readonly: true,
          fieldName: 'calcReceiveAmount'
        },
        {
          type: 'INPUT_NUMBER',
          label: '去零',
          isControls: false,
          max: 0,
          min: 0,
          fieldName: 'subObbAmount'
        }
      ];
    },
    async handleConfirm() {
      let formData = await this.$refs.formPanel.GET_FORM_DATA();
      if (formData[0]) return;
      if (formData[1].subObbAmount > this.limitAmount) return notifyAction(`去零金额不能超过系统去零限额：${this.limitAmount}`, 'warning');
      this.$emit('onConfirm', formData[1]);
    },
    handleCancel() {
      this.$emit('close');
    }
  }
};
</script>
